﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace DataAccess_Layer
{
    public class FileReader
    {
        /// <summary>
        /// Reads a file by a path.
        /// </summary>
        /// <param name="path">The path to search the file on.</param>
        /// <returns></returns>
        public object Read(string path)
        {
            object project = null;
            try
            {
                Stream stream = File.Open(path, FileMode.Open);
                BinaryFormatter binaryFormatter = new BinaryFormatter();

                project = (object)binaryFormatter.Deserialize(stream);
                stream.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace +  "/r/n/r/n");
                Console.WriteLine("Crashed whilst opening file: " + path);
            }
            return project;
        }
    }
}
